package cn.service.marketingService.MarketingServiceImpl;

import cn.service.marketingService.AdlistService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import entity.marketingEntity.Adlist;
import entity.marketingEntity.AdlistCondition;
import entity.Result;

import mapper.marketingMapper.AdlistMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author 朱颢阳
 * @description
 * @time 2024/8/30 18:59
 */
@Service
public class AdlistServiceImpl implements AdlistService {
    @Resource
    AdlistMapper mapper;

    @Override
    public Result getAdlist(AdlistCondition condition) {
        PageHelper.startPage(condition.getCurrentPage(),condition.getPageSize());
        Page<Adlist> page= (Page<Adlist>) mapper.getAdlist(condition);
        System.out.println(page.getTotal());
        return Result.success((int)page.getTotal(),page.getResult());
    }

    @Override
    public Result updateAdlistState(Integer id, Integer state) {
        if (mapper.updateAdlistState(id,state)>0){
            return Result.success("切换成功");
        }else{
            return Result.failed(500,"切换失败");
        }
    }

    @Override
    public Result addAdlist(Adlist adlist) {
        if (mapper.insertSelective(adlist)>0){
            return Result.success("添加成功");
        }else{
            return Result.failed(500,"添加失败");
        }
    }

    @Override
    public Result deleteAdlist(Integer id) {
        if (mapper.deleteByPrimaryKey(id)>0){
            return Result.success("删除成功");
        }else{
            return Result.failed(500,"删除失败");
        }
    }

    @Override
    public Result getAd(Integer id) {
        return Result.success(200,mapper.selectByPrimaryKey(id));
    }

    @Override
    public Result updateAdlist(Adlist adlist) {
        if (mapper.updateByPrimaryKeySelective(adlist)>0){
            return Result.success("更新成功");
        }else{
            return Result.failed(500,"更新失败");
        }
    }
}
